package com.my.yc.homework;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

@WebServlet(name = "ShowItemServlet", value = "/ShowItemServlet")
public class ShowItemServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        // 获取网站中的会话
        HttpSession session = request.getSession();
        String[] like = (String[]) session.getAttribute("like");
        Enumeration<String> names = session.getAttributeNames();
        names.nextElement();
        PrintWriter out = response.getWriter();
        int cnt = 0;
        out.printf("我的like:<br>%s<br>",like[0]);
        for (int i = 1; i < like.length; i++){
            out.printf("%s<br>",like[i]);
        }

        while (names.hasMoreElements()) {
            String name = names.nextElement();
//            if (name == "like" && cnt == 0){
//                cnt ++;
//            }
//            if (name == "like" && cnt != 0){
//                out.printf("<br>%s<br>",session.getAttribute(name));
//                continue;
//            }
            out.printf("我的%s:<br>%s<br>",name,session.getAttribute(name));
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
